package com.sevencar.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;

public class FileUtils {

	public static void copyAssetsDatabaseToData(Context context, String fileName){
        final String addstr="/data/data/com.sevencar/databases/";//里面的包名换成你自己的
        File file = new File(addstr);
        if(!file.exists()){
        	file.mkdir();
        }
        File dbFile = new File(addstr+fileName);
        if(dbFile.exists()){
        	System.out.println("数据库已经存");
        }else{
        	System.out.println("数据库不存在");
        	InputStream assetsDB;
    		try {
    			assetsDB = context.getAssets().open(fileName);
    			 OutputStream dbOut = new FileOutputStream(dbFile);//strout是你要保存的文件

    	        	byte[] buffer = new byte[1024];
    	        		int length;
    	        		while ((length = assetsDB.read(buffer)) > 0) {
    	        			dbOut.write(buffer, 0, length);
    	        		}

    	        		dbOut.flush();
    	        		dbOut.close();
    	        		assetsDB.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
        }
        
    }

}
